<?php

session_start();
$name = $_SESSION['name'];


?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="../../static/js/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/css/view.css"/>
    <title></title>
    <style>
        #test10 {
            margin-left: 100px;
        }
        .imgCss {
            margin-left: 20px;
            height: 200px;
            cursor: pointer;
        }
    </style>
</head>
<body class="layui-view-body">
<div class="layui-content">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-header">新增bug</div>
            <form class="layui-form layui-card-body" id="bugShow" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">产品</label>
                    <div class="layui-input-block">
                        <select name="product" id="product" lay-filter="product">
                            <option value=""></option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">平台</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="platfrom" value="PC" title="PC">
                        <input type="checkbox" name="platfrom" value="android" title="android">
                        <input type="checkbox" name="platfrom" value="ios" title="ios">
                        <input type="checkbox" name="platfrom" value="安卓平板" title="安卓平板">
                        <input type="checkbox" name="platfrom" value="苹果平板" title="苹果平板">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">负责人</label>
                    <div class="layui-input-block">
                        <select name="person" id="person" lay-filter="person">
                            <option value=""></option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">bug标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" id="title" required lay-verify="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">版本号</label>
                    <div class="layui-input-block">
                        <input type="number" name="version" required lay-verify="version" id="version" placeholder="请输入版本号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        <script id="container" name="content" type="text/plain">
                        </script>
                    </div>
                </div>
                <br>
                <br>
                <div class="layui-form-item" style="margin-top: 20px">
                    <div class="layui-inline">
                        <label class="layui-form-label">新建人</label>
                        <div class="layui-input-inline">
                            <input name="new_name" class="layui-input" type="text" disabled autocomplete="off"
                                   value="<?php echo $name ?>" lay-verify="new_name">

                        </div>

                    </div>
                </div>
                <br>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <a class="layui-btn layui-btn-blue" lay-submit lay-filter="addNewBug">立即提交</a>
                        <button type="reset" onclick="reset()" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- 配置文件 -->
<script type="text/javascript" src="../../static/uedit/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../../static/uedit/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container', {
        toolbars: [
            ['snapscreen', 'fullscreen', 'undo', 'redo', 'bold', 'underline', 'insertvideo', 'forecolor', 'scrawl', 'template', 'emotion']
        ],
        initialFrameHeight: 240,
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });
</script>

<script type="text/javascript" src="../../static/js/jquery-3.3.1.min.js"></script>
<script src="../../static/js/layui/layui.all.js"></script>
<script type="text/javascript">
    //定义存储的图片数组
    var img_arr = new Array();
    $(document).ready(function () {
        selectPerson();
        selectProject();
    });
    //重置
    function reset() {
        document.getElementById("title").reset();
    }
    layui.use('form', function () {
        var form = layui.form;
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 1) {
                    return '标题太短';
                }
            },
        });
        //监听提交
        form.on('submit(addNewBug)', function (data) {
            $product = $("#product").val();
            $interest = $("#person").val();
            $version = $("#version").val();
            if ($product == "") {
                layer.msg("未选择产品",{icon:5});
                return false;
            }
            text = $("input:checkbox[name='platfrom']:checked").map(function (index, elem) {
                return $(elem).val();
            }).get().join(',');
            if (text == "") {
                layer.msg("未选择平台");
                return false;
            }
            if ($interest == "") {
                layer.msg("未选择负责人");
                return false;
            }
            if ($version == "") {
                layer.msg("版本信息也很重要哦", {icon: 5});
                return false;
            }
            var data = data.field;
            $name = data.new_name;
            img_arr = JSON.stringify(img_arr);

            $.ajax({
                type: 'post',
                cache: 'false',
                url: '../controller/add_bug.php',
                data: {
                    "data": data,
                    "platfrom": text,
                },
                dataType: 'json',
                success: function (res) {
                    layer.msg(res.message);
                    if (res.code == 200) {
                        $("#imgDiv").children().remove();
                        $("#container").val("");
                        $("#title").val("");
                        img_arr = [];
                        ue.setContent('');
                        // reset();
                    }


                    return false;


                },
                error: function (dat) {
                    layer.msg("添加失败");
                    return false;

                }


            });

            return false;


        });
    });
    //负责人选择框
    function selectPerson() {
        $.ajax({
            type: 'post',
            cache: 'false',
            url: '../controller/query_user.php',
            data: {},
            dataType: 'json',
            success: function (res) {


                $dat = res.data;
                $count = $dat.length;
                var select_person = document.getElementById("person");
                for ($i = 0; $i < $count; $i++) {

                    select_person.innerHTML += "<option value='" + $dat[$i].name + "' >" + $dat[$i].name + "</option>";


                }
                layui.use('form', function () {
                    var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
                    form.render();
                    form.render('select', 'select_person'); //刷新select选择框渲染
                });


            },
            error: function (res) {
                console.log("加载失败");
            }


        });


    }
    //项目选择
    function selectProject() {
        $.ajax({
            type: 'post',
            cache: 'false',
            url: '../controller/project.php',
            data: {},
            dataType: 'json',
            success: function (res) {
                $dat = res.data;
                $count = $dat.length;
                var product = document.getElementById("product");
                for ($i = 0; $i < $count; $i++) {
                    product.innerHTML += "<option value='" + $dat[$i].name + "' >" + $dat[$i].name + "</option>";
                }
                layui.use('form', function () {
                    var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
                    form.render();
                    form.render('select', 'select_person'); //刷新select选择框渲染
                });


            },
            error: function (res) {
                console.log("加载失败");
            }


        });


    }
</script>
</body>
</html>